package com.ipcoder;

import com.sun.security.ntlm.Server;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Tcprecise {
    public static void main(String[] args) throws IOException {
        while (true) {
            //1.创建ServerSocket
            ServerSocket sk = new ServerSocket(9999);
            //2.得到socket
            Socket s = sk.accept();
            //3.得到输入流
            InputStream is = s.getInputStream();
            //4.创建字节数组
            byte[] bys = new byte[4096];
            //5.数组接收输入流的数据
            int len = is.read(bys);
            //6.字符串接收字节数组
            String data = new String(bys, 0, len);
            //控制台打印数据
            System.out.println("您接收的数据:" + data);
            //关闭流,关闭套接字
            is.close();
            sk.close();
            //Accept();
        }
    }

    public static void Accept() throws IOException {
        while (true) {
            //1.接收端创建接收端口号的服务器套接字
            ServerSocket sk = new ServerSocket(10000);
            //2.获得接收端的套接字
            Socket s = sk.accept();
            //3.获得输入流
            InputStream is = s.getInputStream();
            //创建数组
            byte[] bys = new byte[4096];
            //读取去输入流中的数据
            int len = is.read(bys);
            //将得到的数据存入字符串
            String data = new String(bys, 0, len);
            //控制台打印字符串数据
            System.out.println("数据是：" + data);
            sk.close();
            s.close();
        }
    }
}
